<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>客户组管理管理</title>
	<meta name="decorator" content="default"/>
</head>
<body>
	<form:form id="searchForm" modelAttribute="customerGroup" action="${ctx}/base/customerGroup/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input type="button" value="客户群添加" data-inline="true" onclick="loginPasswordPopup('${ctx}/base/customerGroup/form')">
		<label>群名称 ：</label>
		<form:input id="groupName" path="groupName" htmlEscape="false" maxlength="50" type="search" data-inline="true"/>
		<input id="btnSubmit" type="submit" value="查询" data-inline="true"/>
		<input id="btnExport" type="button" data-inline="true" value="导出"/>
	</form:form>
	<div class="icon-buttons">
		<input type="button" class="leave-clean-session" data-inline="true" data-icon="back" data-iconpos="notext" value="返回"/>
	</div>
	<tags:message content="${message}"/>
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead><tr><th>群名称</th><th>所属门店</th><th>群成员数量</th><th>操作</th></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="customerGroup">
			<tr id="${customerGroup.id}">
				<td>${customerGroup.groupName}</td>
				<td>${customerGroup.store.name}</td>
				<td><label id="${customerGroup.id}-number">${fn:length(fns:getCustomerGroupNumber(customerGroup.id))}</label></td>
				<td class="operateTD" id="${customerGroup.id}" >
					<input type="button" data-inline="true" data-icon="arrow-d" data-iconpos="notext">
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#contentTable tbody tr").on("click", function(){
				$("#contentTable tbody tr").removeClass("select_active");
				$(this).addClass("select_active");
				var url = "${ctx}/base/customerGroupDetail/list?groupId="+this.id;
				window.location.href = url;
			});
			if(global.isMobile()) {
				$("#btnExport").parent().css("display", "none");
			} else {
			 	$("#btnExport").click(function(){
			 		global.confirm("确认要导出客户群数据吗？", exportExcel);
				});
			}
		 	$("body").click(function(e){
				$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
				$(".opreationTR").removeClass("opreationTR");
				$(".opreation").remove();
			});
		 	$(".operateTD").click(function(){
				operateMenu(this.id);
			});
		});
		var item;
		function operateMenu(id){
			item = $("#opreation-"+ id);
			$(".opreationTR").removeClass("opreationTR");
			$(".ui-icon-arrow-u").removeClass("ui-icon-arrow-u").addClass("ui-icon-arrow-d");
			if(item.length > 0) {
				item.remove();
				this.event.stopPropagation();
				return;
			}
			var number = $("#" + id + "-number").html();
			$("#"+id + " .ui-icon-arrow-d").removeClass("ui-icon-arrow-d").addClass("ui-icon-arrow-u");
			$(".opreation").remove();
			var html = "<tr id='opreation-" + id + "' class='opreation'><td colspan='4'>";
				html += "<a class='menu-modify' style='width:1.8em;' data-icon='edit' data-iconpos='notext' data-role='button' data-inline='true' href='#'>修改</a>";
				html += "<a class='menu-del' style='width:1.8em;' data-icon='delete' data-iconpos='notext' data-role='button' data-inline='true' href='#'>删除</a></td></tr>";
			var modify = function(){
				bossPasswordPopup("${ctx}/base/customerGroup/form?id=" + id);
			};
			var del = function(){
				if (number && number != 0) {
					showTip("请进入该群并删除全部群成员后，再删除本群！");
				} else {
					bossLoginDeletePopup("确定删除此客户群？", "${ctx}/base/customerGroup/delete?id=" + id);
				}
			};
			$(".menu-modify").die().live('click',modify);
			$(".menu-del").die().live('click',del);
			$("#" + id).addClass("opreationTR");
			$("#" + id).after(html);
			$("#contentTable").trigger("create");
			this.event.stopPropagation();
		}
		function exportExcel(){
			var url = "${ctx}/base/customerGroup/export?groupName="+ $("#groupName").val();
			window.location.href = url;
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
	       	return false;
	    }
	</script>
</body>
</html>
